

  
  
  
  

new Vue({
  el: "#app",
  data() {
    return {
      pickerOptions1: {
        disabledDate(time) {
          return time.getTime() > Date.now();
        },
        shortcuts: [{
          text: '今天',
          onClick(picker) {
            picker.$emit('pick', new Date());
          }
        }, {
          text: '昨天',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24);
            picker.$emit('pick', date);
          }
        }, {
          text: '一周前',
          onClick(picker) {
            const date = new Date();
            date.setTime(date.getTime() - 3600 * 1000 * 24 * 7);
            picker.$emit('pick', date);
          }
        }]
      },
      // 未读消息数量
      messageNum:null,
      // 聊天
      goeasy:{}, 
      im:{},
      // 其他用户消息
      others:[],
      // 其他用户id
      otherIds:[],
      // 个人交易数量
      deals: [],
      // 日志表单
      logForm: {},
      // 个人发布商品类别数量
      categories: [],
      // 个人订单评价数量
      appraises: [],
      //需要审核的商品id(管理员)
      goodsId_checking: '',
      //需要审核的商品id(个人)
      goodsId_mychecking: '',
      // 需要完成的订单id
      needCompleteOrderId: null,
      // 查询自己购买的订单id
      orderId_mybuy: '',
      // 查询自己卖出的订单id
      orderId_mysell: '',
      // 评价
      appraise: null,
      // 修改用户信息表单
      updateUserForm: {},
      //我的订单
      myorders: [],
      // 所有订单
      orders: [],
      //我的卖出订单
      mysellorders: [],
      // 搜索用户
      searchUser: '',
      // 搜索自己商品
      searchGoods_me: '',
      // 搜索模式
      select_mode: '1', // 商品
      select_mode_user: '1', // 用户
      // 发布的商品
      goods: [],
      // 待审核的商品
      goods_checking: [],
      // 所有待审核的商品
      goods_checking_all: [],
      // 所有的商品
      allgoods: [],
      // 所有管理的商品
      allgoods_level: [],
      // 显示切换
      show_content: {
        i1: true,
        i2: false,
        i3: false,
        i4: false,
        i5: false,
        i6: false,
        i7: false,
        i8: false,
        i9: false,
        i10: false
      },
      // 修改密码表单
      userPasswordForm: {},
      // 用户权限修改表单
      userLevelForm: {},
      user: {},
      users: [],
      userGoodsForm: {},
      // 发布商品弹窗
      dialogVisible_newgoods: false,
      // 修改密码弹窗
      dialogVisible_password: false,
      // 日志
      dialogVisible_log: false,
      // 评价弹窗
      dialogVisible_appraise: false,
      // 图片url
      url: '',
      // 头像url
      headUrl: '',
      // 发布商品表单
      userNewgoodsForm: {},
      // 新增用户表达
      newUserForm: {},
      // 新增用户表单弹窗
      dialogVisible_newuser: false,
      // 修改用户权限弹窗
      openForm_newuserlevel: false,
      // 修改修改用户信息弹窗
      openForm_userinformation: false,
      options: [{ // 1
        value: 1,
        label: '服装',
        children: [{
          value: 1,
          label: '男装',
        }, {
          value: 2,
          label: '女装',
        }, {
          value: 3,
          label: '鞋包',
        }, {
          value: 4,
          label: '其他',
        },]
      }, {
        value: 2, // 2
        label: '数码',
        children: [{
          value: 5,
          label: '手机用品',
        }, {
          value: 6,
          label: '电脑用品',
        }, {
          value: 7,
          label: '相机',
        }, {
          value: 8,
          label: '其他',
        },]
      }, {
        value: 3, // 3
        label: '电器',
        children: [{
          value: 9,
          label: '厨房小电',
        }, {
          value: 10,
          label: '个户健康',
        }, {
          value: 11,
          label: '清洁电气',
        }, {
          value: 12,
          label: '其他',
        },]
      }, {
        value: 4, // 4
        label: '医药',
        children: [{
          value: 13,
          label: '皮肤五官',
        }, {
          value: 14,
          label: '消化内科',
        }, {
          value: 15,
          label: '风湿骨外',
        }, {
          value: 16,
          label: '其他',
        },]
      }, {
        value: 5, // 5
        label: '食品',
        children: [{
          value: 17,
          label: '休闲食品',
        }, {
          value: 18,
          label: '方便速食',
        }, {
          value: 19,
          label: '乳饮冲饮',
        }, {
          value: 20,
          label: '其他',
        },]
      }, {
        value: 6, // 6
        label: '书籍',
        children: [{
          value: 21,
          label: '教材',
        }, {
          value: 22,
          label: '教育考试',
        }, {
          value: 23,
          label: '文娱',
        }, {
          value: 24,
          label: '其他',
        },]
      },],
      selectedOptions3: [1, 1]

    }
  },
  methods: {
    // 切换显示
    changeShow(index) {
      let _this = this
      for (let key in _this.show_content) {
        console.log(key)
        console.log(index)
        console.log(index == key)
        if (key == index) {
          _this.show_content[key] = true
        } else {
          _this.show_content[key] = false
        }
      }
      console.log(_this.show_content)
    },


    // 获取用户详细信息
    getMe() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/users/me",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        _this.user = resp.data.data
        console.log(resp.data.data.profile)

      })
    },
    // 获取全部用户详细信息
    getAllUser() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/users/all",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {

        if (!resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        } else {
          _this.users = resp.data.data
          console.log(resp.data.data.profile)
        }


      })
    },

    // 获取全部订单详细信息
    getAllOrders() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/orders/all",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {

        if (!resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        } else {
          _this.orders = resp.data.data
          console.log(resp.data.data.profile)
        }


      })
    },

    // 获取自己所有购买商品订单详细信息
    getAllMyBuyOrder() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/orders/buyorders",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {

        if (!resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        } else {

          _this.myorders = resp.data.data
          for (i = 0; i < _this.myorders.length; i++) {
            item = _this.myorders[i]
            console.log(item)
            item.datetime = _this.formatDate(new Date(item.datetime))
          }
          console.log(resp.data.data.profile)
        }


      })
    },



    // 获取自己所有卖出商品订单详细信息
    getAllMySellOrder() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/orders/sellorders",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {

        if (!resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        } else {

          _this.mysellorders = resp.data.data
          for (i = 0; i < _this.myorders.length; i++) {
            item = _this.myorders[i]
            console.log(item)
            item.datetime = _this.formatDate(new Date(item.datetime))
          }
          console.log(resp.data.data.profile)
        }


      })
    },

    // 查询订单 mode:1 买入 2 卖出 3 管理员查询
    searchOrder(mode) {
      let orderId = ''
      if (mode == 1 && this.orderId_mybuy == '') {

        this.getAllMyBuyOrder()
        return
      } else if (mode == 2 && this.orderId_mysell == '') {
        this.getAllMySellOrder()
        return
      } else {
        this.getAllOrders()
      }
      mode == 1 ? orderId = this.orderId_mybuy : orderId = this.orderId_mysell

      let _this = this;
      axios({
        method: "get",
        url: "http://localhost:8088/orders/select/" + mode + "/" + orderId,
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {

        if (!resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        } else {
          if (mode == 1) {
            _this.myorders = resp.data.data
            for (i = 0; i < _this.myorders.length; i++) {
              item = _this.myorders[i]
              console.log(item)
              item.datetime = _this.formatDate(new Date(item.datetime))
            }
          } else if (mode == 2) {
            _this.mysellorders = resp.data.data
            for (i = 0; i < _this.mysellorders.length; i++) {
              item = _this.mysellorders[i]
              console.log(item)
              item.datetime = _this.formatDate(new Date(item.datetime))
            }
          } else if (mode == 3) {
            _this.orders = resp.data.data
            for (i = 0; i < _this.orders.length; i++) {
              item = _this.orders[i]
              console.log(item)
              item.datetime = _this.formatDate(new Date(item.datetime))
            }
          }

        }


      })
    },

    // 重置订单评价
    resetAppraise(orderId) {
      let _this = this
      this.$confirm('是否要重置该订单评价?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios({
          method: "get",
          url: "http://localhost:8088/orders/resetappraise/" + orderId,
          headers: {
            authorization: localStorage.authorization
          }
        }).then(function (resp) {

          if (resp.data.flag) {
            _this.$message({
              message: resp.data.message,
              type: 'success'
            });
          } else {
            _this.$message({
              message: resp.data.message,
              type: 'error'
            });
          }
          _this.getAllOrders()
        })
      })
    },

    // 取消订单
    cancelOrder(orderId) {
      let _this = this
      this.$confirm('是否取消该订单?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        axios({
          method: "get",
          url: "http://localhost:8088/orders/cancel/" + orderId,
          headers: {
            authorization: localStorage.authorization
          }
        }).then(function (resp) {

          if (resp.data.flag) {
            _this.$message({
              message: resp.data.message,
              type: 'success'
            });
          } else {
            _this.$message({
              message: resp.data.message,
              type: 'error'
            });
          }
          _this.getAllMyBuyOrder()
          _this.getAllMySellOrder()

        })
      })
    },



    // 筛选交易方式标签-----------------
    resetDateFilter() {
      this.$refs.filterTable.clearFilter('date');
    },
    clearFilter() {
      this.$refs.filterTable.clearFilter();
    },
    formatter(row, column) {
      return row.address;
    },
    filterDealWayTag(value, row) {
      return row.dealWay === value;
    },
    filterGenderTag(value, row) {
      return row.gender === value;
    },
    filterLevelTag(value, row) {
      return row.level === value;
    },
    filterTag(value, row) {
      return row.categoryNameF === value;
    },
    filterHandler(value, row, column) {
      const property = column['property'];
      return row[property] === value;
    },
    tagSelect(tag) {
      // alert(tag)

      if (tag == '服装') {
        return ''
      } else if (tag == '数码' | tag == 2) {
        return 'success'
      } else if (tag == '电器') {
        return 'info'
      } else if (tag == '医药' | tag == 1) {
        return 'warning'
      } else if (tag == '书籍' | tag == 3) {
        return 'danger'
      } else return ''
    },
    // ------------------筛选标签

    // 打开商品添加表单
    openForm_newgoods() {
      this.dialogVisible_newgoods = true

    },
    // 打开用户添加表单
    openForm_newuser() {
      this.dialogVisible_newuser = true
    },

    // 关闭商品添加表单
    onClose_newuser() {
      this.dialogVisible_newuser = false;
      // this.getMyGoods();
    },
    // 关闭商品添加表单
    onClose_newgoods() {
      this.dialogVisible_newgoods = false;
      // this.getMyGoods();
    },
    // 添加弹窗
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => { });
    },
    // 添加重置
    addRest() {
      this.userNewgoodsForm = {}
    },

    // 添加用户重置
    addUserRest() {
      this.newUserForm = {}
    },
    // 添加商品
    addGoods() {
      let _this = this;

      if (this.userNewgoodsForm.price == null || this.userNewgoodsForm.goodsName == null
        || this.userNewgoodsForm.goodsContent == null
        || this.userNewgoodsForm.dealWay == null
      ) {
        this.$message({
          message: "请补充必要信息",
          type: 'warning'
        })
        return
      }
      if (_this.url != "") {
        this.userNewgoodsForm.goodsImg = _this.url
        _this.url = ""
      } else {
        this.userNewgoodsForm.goodsImg = "https://www.baomidou.com/img/logo.svg"
      }

      this.userNewgoodsForm.categoryId = this.selectedOptions3[1]


      axios({
        method: "post",
        url: "http://localhost:8088/goods/publish",
        headers: {
          "authorization": localStorage.authorization,
          "Content-Type": "application/json"
        },
        data: _this.userNewgoodsForm

      }).then(function (resp) {
        if (resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'success'
          })

        } else {
          _this.$message({
            message: resp.data.message,
            type: 'warning'
          })
        }
        _this.userNewgoodsForm = {}
        _this.onClose_newgoods()
        _this.fileList = []
        _this.getMyGoods()
      }).catch((error) => {
        _this.$message({
          message: "请输入正确的格式！",
          type: 'error'
        })
      })
    },



    // 添加用户
    addUser() {
      let _this = this;

      if (this.newUserForm.username == null || this.newUserForm.phoneNumber == null
        || this.newUserForm.email == null
        || this.newUserForm.gender == null || this.newUserForm.password == null
      ) {
        this.$message({
          message: "请补充必要信息",
          type: 'warning'
        })
        return
      }
      if (_this.headUrl != "") {
        this.newUserForm.profile = _this.headUrl
        _this.headUrl = ""
      } else {
        this.newUserForm.profile = "http://ruj8e7h1b.hd-bkt.clouddn.com/403ea32c8c0e4d3eaf8161381c43e957.png"
      }

      axios({
        method: "post",
        url: "http://localhost:8088/users/add",
        headers: {
          "authorization": localStorage.authorization,
          "Content-Type": "application/json"
        },
        data: _this.newUserForm

      }).then(function (resp) {
        if (resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'success'
          })
          _this.newUserForm = {}
          _this.onClose_newuser()
          _this.fileList = []
          _this.getAllUser()
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          })
        }
      }).catch((error) => {
        _this.$message({
          message: "请输入正确的格式！",
          type: 'error'
        })
      })
    },

    //上传商品图片
    uploadGoodsImg(response, file, fileList) {
      this.url = response.data
    },

    //上传头像图片
    uploadHeadImg(response, file, fileList) {
      this.headUrl = response.data
    },

    //限制上传数量
    limit(files, fileList) {
      this.$message({
        message: "只能上传一个图片",
        type: 'warning'
      });
    },


    // 获取我的发布
    getMyGoods() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/goods/publishedgoods",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        _this.goods = resp.data.data
        console.log(resp.data.data)

      })
    },


    // 下架商品
    removeGoods(id) {
      this.$confirm('此操作将永久下架该商品, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let _this = this;
        axios({
          method: "delete",
          url: "http://localhost:8088/goods/remove/" + id,
          headers: {
            authorization: localStorage.authorization
          }
        }).then(function (resp) {
          console.log(resp.data)
          if (resp.data.flag) {
            _this.$message({
              message: resp.data.message,
              type: 'success'
            });
            _this.getMyGoods(1)
          } else {
            _this.$message({
              message: resp.data.message,
              type: 'error'
            });
          }
        })
      })
    },

    // 购买商品
    buyGoods(id) {
      this.$confirm('是否要提交订单购买该商品?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let _this = this;
        axios({
          method: "get",
          url: "http://localhost:8088/orders/create/" + id,
          headers: {
            authorization: localStorage.authorization
          }
        }).then(function (resp) {
          if (resp.data.flag) {
            _this.$message({
              message: "下单成功,请尽快完成交易!",
              type: 'success'
            });
            _this.getAllGoods(1)
          } else {
            _this.$message({
              message: resp.data.message,
              type: 'error'
            });
          }
        })
      })
    },


    // 完成交易
    CompletedDeal(id) {
      this.$confirm('是否要提交订单购买该商品?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let _this = this;
        _this.dialogVisible_appraise = true
        _this.needCompleteOrderId = id
      })
    },



    // 提交评价
    sumbit_appraise() {
      let _this = this;
      axios({
        method: "get",
        url: "http://localhost:8088/orders/complete/" + _this.needCompleteOrderId + "/" + _this.appraise,
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.$message({
            message: "评价成功!" + resp.data.message,
            type: 'success'
          });
          _this.appraise = null
          _this.needCompleteOrderId = null
          _this.dialogVisible_appraise = false
          _this.getAllMyBuyOrder()
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }
      })
    },



    // 删除用户
    removeUser(id) {
      this.$confirm('此操作将永久删除该用户, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let _this = this;
        axios({
          method: "delete",
          url: "http://localhost:8088/users/delete/" + id,
          headers: {
            authorization: localStorage.authorization
          }
        }).then(function (resp) {
          if (resp.data.flag) {
            _this.$message({
              message: resp.data.message,
              type: 'success'
            });

          } else {
            _this.$message({
              message: resp.data.message,
              type: 'error'
            });
          }
          _this.getAllUser()

        })
      })
    },


    // 拒绝通过
    refuseGoods(id) {
      this.$confirm('是否要拒绝通过该商品的审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let _this = this;
        axios({
          method: "delete",
          url: "http://localhost:8088/goods/remove/" + id,
          headers: {
            authorization: localStorage.authorization
          }
        }).then(function (resp) {
          if (resp.data.flag) {
            _this.$message({
              message: resp.data.message,
              type: 'success'
            });

          } else {
            _this.$message({
              message: resp.data.message,
              type: 'error'
            });
          }
          _this.getCheckGoods()

        })
      })
    },


    // 审核通过
    acceptGoods(id) {
      this.$confirm('是否要通过该商品的审核?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        let _this = this;
        axios({
          method: "get",
          url: "http://localhost:8088/goods/accept/" + id,
          headers: {
            authorization: localStorage.authorization
          }
        }).then(function (resp) {
          if (resp.data.flag) {
            _this.$message({
              message: resp.data.message,
              type: 'success'
            });

          } else {
            _this.$message({
              message: resp.data.message,
              type: 'error'
            });
          }
          _this.getCheckGoods()
        })
      })
    },

    // 修改密码
    onUpdate_password() {
      let _this = this
      axios({
        method: "post",
        url: "http://localhost:8088/users/updatepassword/" + _this.userPasswordForm.password + "/" + _this.userPasswordForm.newpassword,
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.$message({
            message: resp.data.message + "请重新登录。",
            type: 'success'
          });
          setTimeout(function () {
            localStorage.clear()// 清除所有
            window.location.href = "./login.html"

          }, 1000)

        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }
      })
    },


    // 获取日志
    get_log() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/logs/verify",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          window.location.href = "http://localhost:8088/logs/get/" + _this.logForm.level + "/" + _this.logForm.date;
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          })
        }
      })
    },


    // 修改用户信息
    updateUser(user) {
      this.openForm_userinformation = true
      this.updateUserForm = user
      let _this = this;

    },

    // 修改用户权限
    onUpdate_level() {
      let _this = this
      axios({
        method: "post",
        url: "http://localhost:8088/users/update/level",
        headers: {
          authorization: localStorage.authorization
        },
        data: _this.userLevelForm
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'success'
          });
          _this.onClose_level();
          _this.userLevelForm = {}
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }

        _this.getAllUser();
      })
    },




    // 修改用户信息
    onUpdate_information() {
      let _this = this
      axios({
        method: "post",
        url: "http://localhost:8088/users/update/information",
        headers: {
          authorization: localStorage.authorization
        },
        data: _this.updateUserForm
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.$message({
            message: resp.data.message,
            type: 'success'
          });
          _this.onClose_userInformation();
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }

        _this.getAllUser();
      })
    },
    // 关闭密码表单
    onClose_password() {
      this.dialogVisible_password = false;
    },

    // 关闭日志表单
    onClose_log() {
      this.dialogVisible_log = false;
    },
    // 打开密码表单
    openForm_password() {

      this.dialogVisible_password = true

    },

    // 打开日志获取表单
    openForm_log() {

      this.dialogVisible_log = true

    },



    // 关闭修改权限表单
    onClose_level() {
      this.openForm_newuserlevel = false;
    },

    // 关闭修改用户信息表单
    onClose_userInformation() {
      this.openForm_userinformation = false;
    },
    // 打开权限表单
    openForm_level() {

      this.openForm_newuserlevel = true

    },

    // 条件查询自己发布的商品
    // mode : 1 - 查询自己发布的商品 2-查询所有可购买商品 3-管理员查询全部商品
    selectGoods(mode) {
      let _this = this
      if (_this.searchGoods_me == '') {
        if (mode == 1) {
          this.getMyGoods();
        } else if (mode == 2) {
          this.getAllGoods(1);
        } else if (mode == 3) {
          this.getAllGoods(2);
        }
        return
      }
      axios({
        method: "get",
        url: "http://localhost:8088/goods/select/" + mode + "/" + _this.select_mode + "/" + _this.searchGoods_me,
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          if (mode == 1) { _this.goods = resp.data.data }
          else if (mode == 2) { _this.allgoods = resp.data.data }
          else if (mode == 3) { _this.allgoods_level = resp.data.data }

        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }
      })
    },





    // 条件查询用户
    selectUser() {
      let _this = this
      if (_this.searchUser == '') {
        this.getAllUser();
        return
      }
      axios({
        method: "get",
        url: "http://localhost:8088/users/select/" + _this.select_mode_user + "/" + _this.searchUser,
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.users = resp.data.data
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }
      })
    },


    // 退出登录
    loginout() {
      let _this=this
      axios({
        method:"GET",
        url: "http://localhost:8088/users/logout",
        headers:{
          authorization:localStorage.authorization
        }
      }).then(function(resp){
        _this.$message({
          message: resp.data.message,
          type: 'success'
        });
      })
      localStorage.clear()// 清除所有
      window.location.href = "./login.html"
    },


    // 时间转换
    formatDate(now) {
      var year = now.getFullYear();  //取得4位数的年份
      var month = now.getMonth() + 1;  //取得日期中的月份，其中0表示1月，11表示12月
      var date = now.getDate();      //返回日期月份中的天数（1到31）
      var hour = now.getHours();     //返回日期中的小时数（0到23）
      var minute = now.getMinutes(); //返回日期中的分钟数（0到59）
      var second = now.getSeconds(); //返回日期中的秒数（0到59）
      return year + "-" + month + "-" + date

    },
    /*
        商品页面
    */

    // 获取所有商品
    getAllGoods(mode) {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/goods/allgoods/" + mode,
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          if (mode == 1)
            _this.allgoods = resp.data.data
          else if (mode == 2)
            _this.allgoods_level = resp.data.data
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }


      })
    },



    // 获取个人待审核商品
    getMyCheckGoods() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/goods/checkinggoods/me",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.goods_checking = resp.data.data
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }


      })
    },


    // 查询待审核商品
    // mode: 1-个人 2-管理员
    selectCheckingGoods(mode) {
      console.log(this.goodsId_mychecking)
      let _this = this
      let orderId = ''
      if (mode == 1 && this.goodsId_mychecking == '') {
        this.getMyCheckGoods()
        return
      } else if (mode == 2 && this.goodsId_checking == '') {
        this.getCheckGoods();
        return
      } else if (mode == 2 && this.goodsId_checking != '') {
        orderId = this.goodsId_checking
      } else if (mode == 1 && this.goodsId_mychecking != '') {
        orderId = this.goodsId_mychecking
      }
      console.log(orderId)
      axios({
        method: "get",
        url: "http://localhost:8088/goods/selectchecking/" + mode + "/" + orderId,
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          if (mode == 1) {
            _this.goods_checking = resp.data.data
          } else if (mode == 2) {
            _this.goods_checking_all = resp.data.data
          }
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }


      })
    },

    // 获取所有待审核商品
    getCheckGoods() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/goods/checkinggoods/all",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.goods_checking_all = resp.data.data
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }

      })
    },



    // 获取个人发布商品类别数量
    getCategories() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/users/category",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.categories = resp.data.data

          // 基于准备好的dom，初始化echarts实例
          var myChart = echarts.init(document.getElementById('main'));

          // 指定图表的配置项和数据
          var option = {

            tooltip: {},
            legend: {
              data: ['发布数量']
            },
            xAxis: {
              data: ["服装", "电器", "食品", "书籍", "医药", "数码"]
            },
            yAxis: {},
            series: [{
              name: '销量',
              type: 'bar',
              data: _this.categories,
              itemStyle: {
                normal: {
                  color: function (params) {
                    //注意，如果颜色太少的话，后面颜色不会自动循环，最好多定义几个颜色
                    var colorList = ['#c23531', '#2f4554', '#61a0a8', '#d48265', '#91c7ae', '#749f83', '#ca8622'];
                    return colorList[params.dataIndex]
                  }
                }
              }
            }]
          };

          // 使用刚指定的配置项和数据显示图表。
          myChart.setOption(option);
        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }

      })
    },


    // 获取个人订单评价
    getAppraise() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/users/appraise",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.appraises = resp.data.data

          var myChart1 = echarts.init(document.getElementById('main1'));


          myChart1.setOption({
            tooltip: {
              trigger: 'item'
            },
            series: [
              {
                name: '交易评价',
                type: 'pie',
                radius: ['40%', '70%'],
                avoidLabelOverlap: false,
                itemStyle: {
                  borderRadius: 10,
                  borderColor: '#fff',
                  borderWidth: 2
                },
                label: {
                  show: true,
                  position: 'outside'
                },
                labelLine: {
                  show: true
                },
                data: _this.appraises
              }
            ]
          })
          mychart.on('mouseover', function (params) {
            const { name, value } = params.data;
            mychart.setOption({
              title: {
                text: name,
                subtext: value,
                left: 'center',
                top: 'center'
              },
            })
          });


        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }

      })
    },


    // 获取个人交易数
    getDeals() {
      let _this = this
      axios({
        method: "get",
        url: "http://localhost:8088/users/deals",
        headers: {
          authorization: localStorage.authorization
        }
      }).then(function (resp) {
        if (resp.data.flag) {
          _this.deals = resp.data.data

          var xDataArr = ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月']
          var yDataArr = _this.deals
          var option = {
            xAxis: {
              type: 'category',
              data: xDataArr
            },
            yAxis: {
              type: 'value'
            },
            series: [
              {
                type: 'line',
                data: yDataArr

              }
            ]
          }
          var myChart2 = echarts.init(document.getElementById('main2'));
          myChart2.setOption(option)




        } else {
          _this.$message({
            message: resp.data.message,
            type: 'error'
          });
        }

      })
    },

    init(){
  let _this=this
  // 初始化
  this.goeasy  = GoEasy.getInstance({
  host:"hangzhou.goeasy.io",  //若是新加坡区域：singapore.goeasy.io
  appkey:"BC-c8b07025438443e2963028be1d94a8de",
  modules:['im']//根据需要，传入‘pubsub’或'im’，或数组方式同时传入
  });
  this.im=this.goeasy.im
  //建立连接
  this.goeasy.connect({
      id:localStorage.id, //pubsub选填，im必填，最大长度60字符
      data:{"avatar":"/www/xxx.png","nickname":"Neo"}, //必须是一个对象，pubsub选填，im必填，最大长度300字符，用于上下线提醒和查询在线用户列表时，扩展更多的属性
      onSuccess: function () {  //连接成功
          console.log("GoEasy connect successfully.") //连接成功
      },
      onFailed: function (error) { //连接失败
          console.log("Failed to connect GoEasy, code:"+error.code+ ",error:"+error.content);
      },
      onProgress:function(attempts) { //连接或自动重连中
          console.log("GoEasy is connecting", attempts);
      }
      });


  this.im.latestConversations({
        onSuccess: function (result) { 

          console.log(result)

        },
        onFailed: function (error) { //获取失败
            console.log("Failed to get the latest conversations, code:" + error.code + " content:" + error.content);
        },
    });


    var onConversationsUpdated = function(conversations) {
      _this.messageNum=conversations.conversations.length
      //更新后的最新会话列表
      _this.unreadTotal=conversations.unreadTotal
      for(let i=0;i<conversations.conversations.length;i++){
        _this.otherIds.push(conversations.conversations[i].userId)

      }
      _this.otherIds=Array.from(new Set(_this.otherIds))
      console.log(_this.otherIds)
      console.log(conversations)
      _this.getOthers(_this.otherIds)
    };
    //监听会话列表更新
  this.im.on(GoEasy.IM_EVENT.CONVERSATIONS_UPDATED, onConversationsUpdated);
    },


        // 聊天跳转
        goChat(id){
          if(id==localStorage.id){
            this.$message({
              message: "禁止与自己对话",
              type: 'warning'
            });
            return
          }
          this.im.markPrivateMessageAsRead({
          userId:id,  //聊天对象的userId
          onSuccess: function () { //标记成功
              console.log("Marked as read successfully."); 
              
          },
          onFailed: function (error) { //标记失败
              console.log("Failed to mark as read, code:" + error.code + " content:" + error.content);
          }   
      });
          window.location.href="chat.html?me="+localStorage.id+"&to="+id
  },
  // 获取其他人信息
  getOthers(ids){
    let _this=this
    axios({
      method:"POST",
      url: "http://localhost:8088/users/others",
      data:_this.otherIds,
      headers:{
        authorization:localStorage.authorization
      }
    }).then(function(resp){
      _this.others=resp.data.data
      console.log("获取其他人消息")
      console.log(resp.data)
    })
  },



  },

  mounted() {
    let _this = this
    this.init()
    this.getMe()
    this.authorization = localStorage.authorization
    this.getCategories()
    this.getAppraise()
    this.getDeals()
  }
})


